import Vue from "vue";
import VueRouter from "vue-router";
import NProgress from "nprogress";
import "nprogress/nprogress.css";

Vue.use(VueRouter);

const originalPush = VueRouter.prototype.push;

VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

NProgress.configure({ showSpinner: false });

const routes = [
  {
    path: "/",
    name: "Yiqing",
    component: resolve => require(["@/views/Yiqing.vue"], resolve)
  },
  
];

const router = new VueRouter({
  routes,
  mode: "history",
});

router.beforeEach((to, from, next) => {
  const userAgent = navigator.userAgent;
  sessionStorage.setItem("user-agent", userAgent);
  NProgress.start();
  next();
});
router.afterEach((to, from) => {
  NProgress.done();
  const toDepth = to.path.split("/").length;
  const fromDepth = from.path.split("/").length;
  to.meta.transition = toDepth < fromDepth ? "fade" : "fade";
});
export default router;
